package thread.Test;

import java.util.concurrent.Executors;
import java.util.concurrent.ExecutorService;

public class ThreadPoolDemo1 {

    public static void main(String[] args) {
        // 创建一个可重用固定线程数的线程池,线程池中最多能同时运行2个线程
        ExecutorService pool = Executors.newFixedThreadPool(2);
        // 创建实现了Runnable接口对象，Thread对象当然也实现了Runnable接口
        Thread ta = new MyThreadH("ta");
        Thread tb = new MyThreadH("tb");
        Thread tc = new MyThreadH("tc");
        Thread td = new MyThreadH("td");
        Thread te = new MyThreadH("te");
        // 将线程放入池中进行执行
        pool.execute(ta);
        pool.execute(tb);
        pool.execute(tc);
        pool.execute(td);
        pool.execute(te);
        // 关闭线程池
        pool.shutdown();
    }
}

class MyThreadH extends Thread {
	
	public MyThreadH(String name){
		super(name);
	}

    @Override
    public void run() {
        System.out.println(Thread.currentThread().getName()+ " is running.");
    }
};
/*
pool-1-thread-1 is running.
pool-1-thread-1 is running.
pool-1-thread-1 is running.
pool-1-thread-1 is running.
pool-1-thread-2 is running.

 * */
